<template>
  <div class="home">
    <Banner />
    <Cate />
    <div
      v-for="l in list"
      :key="l.type"
    >
      <!-- 今日优选 -->
      <Today
        v-if="l.type == 1"
        :data="l"
      />
      <!-- 营家好店 -->
      <GoodShop
        v-if="l.type == 8"
        :data="l"
      />
      <!-- 活动优惠 -->
      <!-- <Activity
        v-if="l.type == 3"
        :data="l"
      /> -->
      <!-- Top单品 -->
		<Ms v-if="l.type == 6"
        :data="l" />
      <TopList
        v-if="l.type == 4"
        :data="l"
      />
      <!-- 即将上线 -->
      <ComingSoon
        v-if="l.type == 5"
        :data="l"
      />
      <!-- 新鲜好物 -->
      <Fresh
        v-if="l.type == 6"
        :data="l"
      />
      <!-- 热门专题 -->
      <HotTopic
        v-if="l.type == 7"
        :data="l"
      />
    </div>
    <Like />
    <About />
  </div>
</template>

<script>
// @ is an alias to /src

import Banner from "../components/home/banner.vue";
import Cate from "../components/home/cate-copy.vue";
import Today from "../components/home/today-copy.vue";
import GoodShop from "../components/home/goodshop-copy.vue";
import Activity from "../components/home/activity.vue";
import TopList from "../components/home/toplist-copy.vue";
import ComingSoon from "../components/home/comingSoon.vue";
import Fresh from "../components/home/fresh.vue";
// import HotTopic from "../components/home/hottopics.vue";
import Like from "../components/common/like.vue";
import About from "../components/common/about.vue";
import Ms from "../components/home/miaosha.vue";
export default {
  name: "Home",
  components: {
    Banner,
    Cate,
    Today,
    GoodShop,
    Activity,
    TopList,
    ComingSoon,
    Fresh,
    // HotTopic,
    Like,
    About,
	Ms
  },
  data() {
    return {
      list: [],
    };
  },
  mounted() {
    if (localStorage.getItem("token")) {
      console.log("token有效");
    } else {
      this.GetCsLogin();
    }
    let that = this;
    if (this.$route.query.mobile) {
      let params = {
        mobile: this.$route.query.mobile,
      };
      this.$api.home.uLoginWithMobile(params).then((res) => {
        // 执行某些操作
        if (res.code == 1) {
          console.log("userInfo", res.data.user);
          localStorage.setItem("token", res.data.token);
          localStorage.setItem("userInfo", JSON.stringify(res.data.user));
          that.$router.push({
            path: "/",
          });
        }
      });
    }
    this.$api.home.pcIndex({}).then((res) => {
      // 执行某些操作
      if (res.code == 1) {
        this.list = res.data;
      }
    });
  },
  methods: {
    GetQueryString(name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
      var r = window.location.search.substr(1).match(reg);
      if (r !== null) return unescape(r[2]);
      return null;
    },
    GetCsLogin() {
      let params = {
        ticket: this.GetQueryString("ticket"),
      };
      if (params.ticket) {
        this.$api.home.casLogin(params).then((res) => {
          console.log("单点登录", res.data);
          if (res.code !== 1) {
            this.$message.error(res.msg);
          } else {
            localStorage.setItem("token", res.data.token);
            localStorage.setItem("userInfo", JSON.stringify(res.data.user));
          }
          // localStorage.setItem("token",res.data)
        });
      }
    },
  },
};
</script>
<style scoped lang="scss">
.home {
  // margin-top: 6.18rem;
  display: flex;
  flex-direction: column;
}
</style>
